<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class NotionDbResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $dt = Carbon::now();
        return [
            "id" => $this->id,
            "db_id" => $this->db_id,
            "template" => json_decode($this->template, true),
            "created_time" => $dt->diffForHumans(Carbon::parse($this->created_at)),
        ];
    }
}
